package com.edgar;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

import java.util.ArrayList;
import java.util.List;

public class FileBox extends Model<FileBox> {

    public static final FileBox dao = new FileBox();

    public static final String FILE_ID = "file_id";
    public static final String URL = "url";
    public static final String FILE_EXTENSION = "file_extension";
    public static final String IS_DELETE = "is_delete";
    public static final String DELETE_TIME = "delete_time";
    public static final String CREATETS = "createts";


    public List<FileBox> findByZoneId(String zoneId) {
        String sql = "select * from t_file_box where zone_id = ?";
        return this.find(sql, zoneId);
    }

    public boolean deleteByZoneId(String zoneId) {
        String sql = "delete from t_file_box where zone_id = ?";
        return Db.delete(sql, zoneId) > 0;
    }


    public Page<FileBox> paginateList(FileBox fileBox, int page, int rows) {
        StringBuilder sql = new StringBuilder();
        sql.append(" from t_file_box where 1 =1 ");
        List<Object> params = new ArrayList<>();
        if (!StrKit.isBlank(fileBox.getStr(FileZone.ZONE_ID))) {
            sql.append("and zone_id = ?");
            params.add(fileBox.getStr(FileZone.ZONE_ID));
        }

        return this.paginate(page, rows, "select *", sql.toString(), params.toArray());

    }

}
